package com.example.za.account.model;


import android.os.Parcel;
import android.os.Parcelable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import java.util.Date;

/**
 * 收入实体类
 */
@DatabaseTable(tableName = "ASincome")
public class Income implements Parcelable {
    @DatabaseField(generatedId = true, columnName = "ASid")
    private int mId;//主键
    @DatabaseField(canBeNull = false, columnName = "ASdate")
    private Date mDate;//日期
    @DatabaseField(canBeNull = false, columnName = "ASamount")
    private float mAmount;//金额
    @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, columnName = "AScategoryId")
    private IncomeCat mCategory; //类别
    @DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, columnName = "ASuserId")
    private User mUser;             //用户
    @DatabaseField(columnName = "ASnote")
    private String mNote;         //备注
    @DatabaseField(columnName = "ASsecond")
    private Long mSecond; //秒  识别符

    public int getmId() {
        return mId;
    }

    public void setmId(int mId) {
        this.mId = mId;
    }

    public Date getmDate() {
        return mDate;
    }

    public void setmDate(Date mDate) {
        this.mDate = mDate;
    }

    public float getmAmount() {
        return mAmount;
    }

    public void setmAmount(float mAmount) {
        this.mAmount = mAmount;
    }

    public IncomeCat getmCategory() {
        return mCategory;
    }

    public void setmCategory(IncomeCat mCategory) {
        this.mCategory = mCategory;
    }

    public User getmUser() {
        return mUser;
    }

    public void setmUser(User mUser) {
        this.mUser = mUser;
    }

    public String getmNote() {
        return mNote;
    }

    public void setmNote(String mNote) {
        this.mNote = mNote;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.mId);
        dest.writeLong(this.mDate != null ? this.mDate.getTime() : -1);
        dest.writeFloat(this.mAmount);
        dest.writeParcelable(this.mCategory, flags);
        dest.writeParcelable(this.mUser, flags);
        dest.writeString(this.mNote);
    }

    public Income() {
    }

    public Income(Date date, float amount, IncomeCat category, User user, String note, Long second) {
        mDate = date;
        mAmount = amount;
        mCategory = category;
        mUser = user;
        mNote = note;
        mSecond = second;
    }

    public Income(Date date, float amount, IncomeCat category, User user, String note) {
        mDate = date;
        mAmount = amount;
        mCategory = category;
        mUser = user;
        mNote = note;
    }

    @Override
    public String toString() {
        return "Income{" +
                "mId=" + mId +
                ", mDate=" + mDate +
                ", mAmount=" + mAmount +
                ", mCategory=" + mCategory +
                ", mUser=" + mUser +
                ", mNote='" + mNote + '\'' +
                '}';
    }

    protected Income(Parcel in) {
        this.mId = in.readInt();
        long tmpMDate = in.readLong();
        this.mDate = tmpMDate == -1 ? null : new Date(tmpMDate);
        this.mAmount = in.readFloat();
        this.mCategory = in.readParcelable(IncomeCat.class.getClassLoader());
        this.mUser = in.readParcelable(User.class.getClassLoader());
        this.mNote = in.readString();
    }

    public static final Parcelable.Creator<Income> CREATOR = new Parcelable.Creator<Income>() {
        @Override
        public Income createFromParcel(Parcel source) {
            return new Income(source);
        }

        @Override
        public Income[] newArray(int size) {
            return new Income[size];
        }
    };

    public Long getmSecond() {
        return mSecond;
    }

    public void setmSecond(Long mSecond) {
        this.mSecond = mSecond;
    }
}
